import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class ModelFactory {

	ArrayList<Student> students=new ArrayList<Student>();
	ArrayList <String> stringOfRequests = new ArrayList<String>();
	ArrayList<Course> courses = new ArrayList<Course>();
	
	public ModelFactory() throws IOException{
		buildStudents();
		moreBuildStudents();
	}
	
	public void buildCourses() throws IOException {
		
		String myFile = "classData.txt";
		Scanner sf = new Scanner(new File(myFile)).useDelimiter(",");
		while (sf.hasNext()) {
			int courseNum = sf.nextInt();
			String TeacherName = sf.next();
			int Term = sf.nextInt();
			int periodNum = sf.nextInt();
			String MeetingDays = sf.next();
			String LabTemp = sf.next();
			boolean Lab;
			if (LabTemp.equals("True")) {
				Lab = true;
			}
			else {
				Lab = false;
			}
			String LabDay = sf.next();
			int LabPeriod = sf.nextInt();
			
			courses.add(new Course(courseNum, TeacherName, Term, periodNum, MeetingDays, Lab, LabDay, LabPeriod));
		}
		sf.close();
	}
	
	public ArrayList<Student> getStudents() {
		return students;
	}

	public ArrayList<Course> getCourses() {
		return courses;
	}

	public void buildStudents() throws IOException{
		File requests = new File("CourseRequests2009");
		Scanner scanMan = new Scanner(requests);
		
		while(scanMan.hasNext()){
			stringOfRequests.add(scanMan.nextLine());
		}
		/*for(String i: stringOfRequests){
			System.out.println(i);
		}*/
	}
	
	public void moreBuildStudents(){
		String [] temp=new String[5];
		String currentID="";
		temp=stringOfRequests.get(0).split(",");
		Student tempS = new Student(Integer.parseInt(temp[0]),Integer.parseInt(temp[1]),temp[2],temp[3]);
		Integer num = new Integer(temp[4]);
		tempS.addCourseNo(num);
		students.add(tempS);
		currentID=temp[0];
		for(int i=1; i<stringOfRequests.size(); i++){
			temp=stringOfRequests.get(i).split(",");
			if(temp[0].equals(currentID)){
				tempS.addCourseNo(Integer.parseInt(temp[4]));
				currentID=temp[0];
				
			}
			else{
				tempS=new Student(Integer.parseInt(temp[0]),Integer.parseInt(temp[1]),temp[2],temp[3]);
				students.add(tempS);
				currentID=temp[0];
			}
			
		}
		
		for(int k=0; k<4; k++){
			System.out.println(students.get(k).getFname()+ " ");
			for(int i=0; i<students.get(k).getCourseNo().size();i++){
				System.out.println(students.get(k).getCourseNo().get(i));
				
			}
		}
		
	}
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try{
			ModelFactory go = new ModelFactory();
			}
			catch(IOException ex){
			
		}
	}

}
